<?php
/*
 * @Description:
 * @Author: twenlike
 * @Date: 2023-05-15 17:28:35
 * @LastEditTime: 2023-05-15 21:32:00
 * @LastEditors: twenlike
 */
namespace app\controller;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// require 'vendor/autoload.php';

use app\BaseController;

class PhpMailerSend extends BaseController
{
    public function __call($name, $arguments)
    {
        return "报错信息:".$name;
    }

    public function Send()
    {
        $mail = new PHPMailer(true);

        try {
            //Server settings
            $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = 'smtp.qq.com';                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = '11111111@qq.com';                     //SMTP username 这里填自己的发件邮箱
            $mail->Password   = 'daweaweaweqweasas';                               //SMTP password 这里就是上边保存的授权码，不是邮箱密码
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
            $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

            //Recipients
            $mail->setFrom('11111111@qq.com', 'kaifazhe');             // '发件人邮箱', '名称'
            $mail->addAddress('222222222@qq.com', 'jieshouzhe');     //Add a recipient '收件人邮箱', '名称'


            // $mail->addAddress('ellen@example.com');               //Name is optional
            // $mail->addReplyTo('info@example.com', 'Information');
            // $mail->addCC('cc@example.com');
            // $mail->addBCC('bcc@example.com');

            // $mail->addAddress('多个收件人邮箱');
            // $mail->addReplyTo('用于接受回复的邮箱', 'Information');
            // $mail->addCC('抄送邮箱');
            // $mail->addBCC('收件人邮箱（能收到邮件但是不会显示邮箱）');

            //Attachments
            // $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
            // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name


            // $mail->addAttachment('这里填要发送的附件的【路径/附件】');
            // $mail->addAttachment('这里填要发送的附件的【路径/附件】', '新名称');

            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'hello test'; // 这里是邮件的主题
            $mail->Body    = 'test</b>test</b>test</b>test</b>验证码是：1111'; //这里是邮件的正文内容
            $mail->AltBody = '哈哈哈哈哈哈呵呵哈哈哈或或或或或或或或或或或或泰库辣'; //这是非html邮件客户端的纯文本正文

            $mail->send();
            echo '信息发送完成！';
        } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error【信息发送失败】: {$mail->ErrorInfo}";
        }
    }

}
